﻿using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using SmartCity.Shared;
using Volo.Abp;
using Volo.Abp.AspNetCore.Mvc;

namespace CommonManagement
{
    /// <summary>
    /// 新闻控制器
    /// </summary>
    [RemoteService]
    [Area("commonManagement")]
    [Route("api/commonManagement/presses")]
    public class PressController : AbpController, IPressAppService
    {
        private readonly IPressAppService _pressAppService;

        public PressController(
            IPressAppService pressAppService)
        {
            _pressAppService = pressAppService;
        }

        // 1.5.5 获取新闻列表
        [HttpGet]
        [Route("list")]
        public Task<ListResponse<PressDto>> PagedListAsync(
            PagedListRequest request,
            string hot = null,
            string publishDate = null,
            string title = null,
            string top = null,
            string type = null)
        {
            return _pressAppService.PagedListAsync(request, hot, publishDate, title, top, type);
        }

        // 1.5.6 获取新闻详细信息
        [HttpGet]
        [Route("{id:int}")]
        public Task<ResultResponse<PressDto>> GetAsync(int id)
        {
            return _pressAppService.GetAsync(id);
        }

        // 1.5.4 新闻点赞
        [Authorize]
        [HttpPut]
        [Route("like/{id:int}")]
        public Task<ActionResponse> LikeAsync(int id)
        {
            return _pressAppService.LikeAsync(id);
        }
    }
}